package com.fafu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class PreparedStatement02 {
    public static void main(String[] args) throws Exception{
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //创建连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=UTF-8","root","root");
        System.out.println(connection);
        //创建要执行的SQL语句
        String sql = "";
        //通过connection实例来创建PrepaaredStatement,将要执行的sql语句放入方法参数中
        PreparedStatement pstm = connection.prepareStatement(sql);
        //执行sql  insert update delete返回的都是受影响的行数excuteUpdate()  select返回的都是临时表excuteQuery()
        int i = pstm.executeUpdate();
        if(i>0){
            System.out.println("操作成功");
        }
        else{
            System.out.println("操作失败");
        }
        pstm.close();
        connection.close();
    }
}
